import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

import Index from '@/views/Index/index.vue'
import {  House, Promotion, DocumentCopy,Management,Files, User, Stamp} from '@element-plus/icons-vue'

export const iconMapping = {
  "house": House,
  "promotion": Promotion,
  "documentCopy": DocumentCopy,
  "management": Management,
  "files": Files,
  "user": User,
  "stamp": Stamp,
}
const routes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'Login',
    meta: {
      showNav: false
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/Login/index.vue')
  },
  {
    path: '/',
    name: 'index',
    component: Index,
    meta: {
      title: '首页',
      showNav: true,
      isShow: true,
      icon: 'house'
    }
  },
  {
    path: '/asset',
    name: 'asset',
    meta: {
      title: '设备管理',
      showNav: false,
      isShow: true,
      icon: 'dashboard'
    },
    children: [
        {
          path: 'equipment',
          component: () => import('@/views/AssetPage/equipment/index.vue'),
          name: 'equipment',
          meta: { title: '设备台账', showNav: true, isShow: true, }
        },
        {
          path: 'equipment/add',
          component: () => import('@/views/AssetPage/equipment/detail.vue'),
          name: 'equipmentAdd',
          meta: { title: '设备新增', showNav: true, isShow: false, active: 'equipment' },
        },
        {
          path: 'equipment/edit/:id',
          component: () => import('@/views/AssetPage/equipment/detail.vue'),
          name: 'equipmentAdd',
          meta: { title: '设备详情', showNav: true, isShow: false, active: 'equipment' }
        },
      {
        path: 'jig',
        component: () => import('@/views/AssetPage/jig/index.vue'),
        name: 'jig',
        meta: { title: '工装台账', showNav: true, isShow: true, }
      },
      {
        path: 'jig/add',
        component: () => import('@/views/AssetPage/jig/detail.vue'),
        name: 'jigAdd',
        meta: { title: '工装新增', showNav: true, isShow: false }
      },
      {
        path: 'jig/edit/:id',
        component: () => import('@/views/AssetPage/jig/detail.vue'),
        name: 'jigAdd',
        meta: { title: '工装详情', showNav: true, isShow: false }
      }
    ]
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
// 挂在路由导航守卫

router.beforeEach((to: any, from, next) => {
  const token = localStorage.getItem("admin-token")
  if (token) {
    next();
  } else {
    if (to.path === "/login") {
      next();
    } else {
      next({ path: "/login" });
    }
  }
});
export default router
